package com.net.model.interceptor;


import com.drug.lib.util.SPManager;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.nio.charset.Charset;

import okhttp3.Credentials;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 版权：星云飞救公司 版权所有
 *
 * @author zhouhequan
 * 版本：1.0
 * 创建日期：2021/10/25 or 9:46
 * 描述：添加token拦截器
 */
public class BasicAuthInterceptor implements Interceptor {
    private static final Charset UTF8 = Charset.forName("UTF-8");

    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {

        Request request = chain.request();
//        if (!SPManager.get()) {
//            String credentials = Credentials.basic("androidApp", "123");
//            Request.Builder builder = request.newBuilder();
//            builder.header("Authorization", credentials);
//            return chain.proceed(builder.build());
//        }
        String token = "bearer " + SPManager.getToken();
        Request.Builder builder = request.newBuilder();
        builder.header("Authorization", token);

        return chain.proceed(builder.build());
    }
}
